<?xml version='1.0' encoding='UTF-8'?>

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	xmlns:a="http://java.sun.com/jsf/composite/custom"
	template="../templates/template.xhtml">

	<ui:define name="metadata">
		<f:event type="preRenderView" listener="#{weeklyImputationsPage.initImputationsPage}" />
	</ui:define>
	
	<ui:define name="pageTitle">#{msg.impImputationsTitle}</ui:define>
	
	<ui:define name="content">
	    <p>
		#{msg.impImputationsPresentation}
	    </p>

	    <p:calendar value="#{weeklyImputationsPage.date}" mode="inline" close="false"
			onselectUpdate="imputationsPanel, section-messages" selectListener="#{weeklyImputationsPage.dateChanged}"
			startWeekday="1"/>

	    <div class="cleared"/>

	    <br />

	    <p:outputPanel id="imputationsPanel">
			<p:panel header="#{weeklyImputationsPage.imputationsPanelTitle}" toggleable="true" toggleSpeed="0">
			    <h:outputFormat value="#{msg.impImputationsSemaine}">
					<f:param value="#{weeklyImputationsPage.weekConsumate}" />
			    </h:outputFormat>
			    <a:impList tableId="imputations" value="#{weeklyImputationsPage.results}" listSize="#{weeklyImputationsPage.resultSize}" />
			</p:panel>
	    </p:outputPanel>

	    <br />

	    <p:panel header="#{msg.impImputationsTachesAffectees}" toggleable="true" toggleSpeed="0">
			<div class="dataTable">
			    <p:dataTable id="tasks" styleClass="dcListe"
					 value="#{taskListPage.results}" var="tsk"
					 paginator="true" paginatorPosition="bottom"
					 lazy="true" dynamic="true" rows="10">
					<p:column sortBy="#{tsk.code}">
					    <f:facet name="header"><h:outputText value="#{msg.tskCreationCode}"/></f:facet>
					    <h:outputText value="#{tsk.code}"/>
					</p:column>
		
					<p:column sortBy="#{tsk.label}">
					    <f:facet name="header"><h:outputText value="#{msg.tskCreationLibelle}"/></f:facet>
					    <h:outputText value="#{tsk.label}"/>
					</p:column>
		
					<p:column sortBy="#{tsk.attachedProject.name}">
					    <f:facet name="header"><h:outputText value="#{msg.tskCreationProjet}"/></f:facet>
					    <h:outputText value="#{tsk.attachedProject.name}"/>
					</p:column>
		
					<p:column sortBy="#{tsk.clientRequest.clientReference}">
					    <f:facet name="header"><h:outputText value="#{msg.tskCreationReferenceDC}"/></f:facet>
					    <h:outputText value="#{tsk.clientRequest.clientReference}"/>
					</p:column>
		
					<p:column>
					    <f:facet name="header"><h:outputText value="#{msg.tskCreationListeCollab}"/></f:facet>
					    <ui:repeat value="#{tsk.assignedEmployees}" var="emp">
							<li><h:outputText value="#{emp.firstName} #{emp.lastName}" /></li>
					    </ui:repeat>
					</p:column>
		
					<p:column>
					    <f:facet name="header"><h:outputText value="#{msg.impImputationsImputerButton}" /></f:facet>
					    <h:commandButton action="IMP_CREATE" value="#{msg.impImputationsImputerButton}"
							     styleClass="button">
							<f:setPropertyActionListener target="#{sess.selectedTask}" value="#{tsk}" />
					    </h:commandButton>
					</p:column>
		
					<ui:insert />
			    </p:dataTable>
			</div>
		 </p:panel>

		<!-- TODO: lazy-loading does not work when composite component is used. Neither do ui:include -->
		<ui:remove>
		    <a:taskList tableId="tasks" value="#{taskListPage.results}" listSize="10" lazy="#{true}">
				<p:column>
				    <f:facet name="header"><h:outputText value="#{msg.impImputationsImputerButton}" /></f:facet>
				    <h:commandButton action="IMP_CREATE" value="#{msg.impImputationsImputerButton}"
						     styleClass="button">
						<f:setPropertyActionListener target="#{sess.selectedTask}" value="#{tsk}" />
				    </h:commandButton>
				</p:column>
		    </a:taskList>
		</ui:remove>
	   
	</ui:define>
	
</ui:composition>